package youcaihuaoa.weetop.com.vm.apply

import android.app.Application
import api.UserServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.configs.AppConstants
import com.robot.base.model.CustomListBean
import com.robot.base.model.CustomListItemBean
import com.robot.base.util.arouter.ARouterUtil
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import me.goldze.mvvmhabit.http.BaseResponse
import youcaihuaoa.weetop.com.R

class MyApplyViewModel(application: Application) : GLBaseViewModel(application) {


    val uiEvent = UIEvent()

    val kqLockData = mutableListOf<CustomListItemBean>()

    val rsLockData = mutableListOf<CustomListItemBean>()

    val xzLockData = mutableListOf<CustomListItemBean>()

    val cwLockData = mutableListOf<CustomListItemBean>()

    init {
        kqLockData.add(CustomListItemBean().apply {
            id = ""
            type = "1"
            title = "请假申请"
            icon = R.mipmap.app_icon_menu_qj
        })
        kqLockData.add(CustomListItemBean().apply {
            id = ""
            type = "2"
            title = "加班申请"
            icon = R.mipmap.app_icon_menu_jb
        })
        kqLockData.add(CustomListItemBean().apply {
            id = ""
            type = "3"
            title = "外勤申请"
            icon = R.mipmap.app_icon_menu_wq
        })
        kqLockData.add(CustomListItemBean().apply {
            id = ""
            type = "4"
            title = "补卡申请"
            icon = R.mipmap.app_icon_menu_bk
        })


        rsLockData.add(CustomListItemBean().apply {
            id = ""
            type = "5"
            title = "转正申请"
            icon = R.mipmap.app_icon_menu_zz
        })
        rsLockData.add(CustomListItemBean().apply {
            id = ""
            type = "6"
            title = "调薪申请"
            icon = R.mipmap.app_icon_menu_tx
        })
        rsLockData.add(CustomListItemBean().apply {
            id = ""
            type = "7"
            title = "权限申请"
            icon = R.mipmap.app_icon_menu_qx
        })
        rsLockData.add(CustomListItemBean().apply {
            id = ""
            type = "8"
            title = "离职申请"
            icon = R.mipmap.app_icon_menu_lz
        })



        xzLockData.add(CustomListItemBean().apply {
            id = ""
            type = "9"
            title = "资料申请"
            icon = R.mipmap.app_icon_menu_zl
        })
        xzLockData.add(CustomListItemBean().apply {
            id = ""
            type = "10"
            title = "用印申请"
            icon = R.mipmap.app_icon_menu_yy
        })
        xzLockData.add(CustomListItemBean().apply {
            id = ""
            type = "11"
            title = "工序审批申请"
            icon = R.mipmap.app_icon_menu_gx
        })
        xzLockData.add(CustomListItemBean().apply {
            id = ""
            type = "12"
            title = "合同审批申请"
            icon = R.mipmap.app_icon_menu_ht
        })

        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "14"
            title = "开票申请"
            icon = R.mipmap.app_icon_menu_kp
        })
        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "13"
            title = "报销申请"
            icon = R.mipmap.app_icon_menu_bx
        })
        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "16"
            title = "劳务申请"
            icon = R.mipmap.app_icon_menu_lw
        })
        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "17"
            title = "工会申请"
            icon = R.mipmap.app_icon_menu_gh
        })
        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "15"
            title = "财务审批"
            icon = R.mipmap.app_icon_menu_cw
        })
        cwLockData.add(CustomListItemBean().apply {
            id = ""
            type = "18"
            title = "薪酬绩效审批"
            icon = R.mipmap.app_icon_menu_xc
        })

    }

    fun refreshMenuData() {
        UserServiceFactory.customList()
            .subscribe(object : AbstractViewModelSubscriber<BaseResponse<CustomListBean>>(this) {
                override fun onNext(t: BaseResponse<CustomListBean>) {
                    uiEvent.menuDataLiveEvent.postValue(t.data)
                }

                override fun onError(e: Throwable) {
                    super.onError(e)
                    uiEvent.menuDataLiveEvent.postValue(CustomListBean().apply {
                        kq_form_data = mutableListOf()
                        rs_form_data = mutableListOf()
                        xz_form_data = mutableListOf()
                        cw_form_data = mutableListOf()
                    })
                }
            })
    }


    class UIEvent {

        val menuDataLiveEvent = SingleLiveEvent<CustomListBean>()

    }

    val clickJumpMyApplyListCommand = BindingCommand<Any>(BindingAction {
        ARouterUtil.goToActivity(AppConstants.Router.Main.A_MY_APPLY_LIST)
    })
}